


typedef struct {
    int* arr;
    int real;
    int front;
    int capacity;
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* pa = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    pa->arr = (int*)malloc(sizeof(int) * (k + 1));
    pa->real = pa->front = 0;
    pa->capacity = k;
    return pa;
}
bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->real == obj->front;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return ((obj->real + 1) % (obj->capacity + 1)) == obj->front;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj)) {
        return false;
    }
    obj->arr[obj->real++] = value;
    obj->real %= obj->capacity + 1;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return false;
    }
    obj->front++;
    obj->front %= obj->capacity + 1;
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    return obj->arr[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    int prev = obj->real - 1;
    if (obj->real == 0)
        prev = obj->capacity;
    return obj->arr[prev];
}



void myCircularQueueFree(MyCircularQueue* obj) {
    if (obj->arr)
        free(obj->arr);
    free(obj);
    obj = NULL;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/